package artibella.core
{
	import artibella.events.NavEvent;
	import artibella.ui.triggers.ITriggerCommand;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	
	import flash.events.EventDispatcher;

	/**
	 * ...
	 * @author pbordachar
	 */

	public class NavTriggerCommand extends EventDispatcher implements ITriggerCommand 
	{
		private var _destination:String;
		private var _cible:String;
		private var _lien:String;
	
		
		public function NavTriggerCommand( go:String, lk:String = "", tg:String ="" )
		{
			_destination = go;
			_lien = lk;
			_cible = tg;
		}
		
		// ----- ITriggerCommand
		
		public function rollOver():void
		{
			if( _destination == "XXX" ){
				Nav.instance.dispatchEvent( new NavEvent( NavEvent.SHOW_LINK, _lien ) );
			} 
		}
		
		public function rollOut():void
		{
			if( _destination == "XXX" ){
				Nav.instance.dispatchEvent( new NavEvent( NavEvent.SHOW_LINK, "" ) );
			} 
		}
			
		public function click():void
		{
			if ( _destination == "XXX" ) {
				navigateToURL( new URLRequest(  _lien ), _cible );
			} else {
				Nav.instance.dispatchEvent( new NavEvent( NavEvent.CALL, _destination ) );
			}
		}
		
		public function compare( s:String ):Boolean
		{
			if( s.indexOf( _destination ) == 0 ){
				
				return true;
			}
			
			return false;
		}
	}
}
